import request from '@/axios'
import { RoleSaveData, RoleDetailData, RolePageData, RolePageParams } from '@/api/role/types'

export const getRoleListApi = (params: RolePageParams): Promise<IResponse<RolePageData[]>> => {
  return request.get({ url: '/roles/page', params })
}

export const getRoleDetailApi = (code: string): Promise<IResponse<RoleDetailData>> => {
  return request.get({ url: `/roles/detail/${code}` })
}

export const addRoleApi = (data: RoleSaveData): Promise<IResponse> => {
  return request.post({ url: '/roles/create', data })
}

export const updateRoleApi = (data: RoleSaveData): Promise<IResponse> => {
  return request.put({ url: `/roles/update/${data.code}`, data })
}

export const deleteRoleApi = (code: string): Promise<IResponse> => {
  return request.delete({ url: `/roles/delete/${code}` })
}
